/*
 * Copyright (C) 2011 bus.fm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.busfm.download;

import com.busfm.model.DownloadEntity;
import com.busfm.model.SongEntity;

/**
 * <p>
 * Title:DownloadJob
 * </p>
 * <p>
 * Description:DownloadJob
 * </p>
 * <p>
 * Copyright (c) 2011 www.bus.fm Inc. All rights reserved.
 * </p>
 * <p>
 * Company: bus.fm
 * </p>
 * 
 * 
 * @author jingguo0@gmail.com
 * 
 */
public class DownloadJob {
	private DownloadEntity mDownloadEntity;
	private DownloadJobListener mDownloadJobListener;

	private int mStartId;
	private int mProgress;
	private int mTotalSize;
	private int mDownloadedSize;
	private String mDestination;

	public DownloadJob(DownloadEntity downloadEntity, int startId) {
		mDownloadEntity = downloadEntity;
		mStartId = startId;
	}

	public void onStart() {
	}

	public void setListener(DownloadJobListener listener) {
		mDownloadJobListener = listener;
	}

	public int getProgress() {
		return mProgress;
	}

	public void setProgress(int progress) {
		mProgress = progress;
	}

	public void setTotalSize(int totalSize) {
		mTotalSize = totalSize;
	}

	public int getTotalSize() {
		return mTotalSize;
	}

	// set the store path
	public void setDestination(String destination) {
		mDestination = destination;
	}

	public String getDestination() {
		return mDestination;
	}

	public DownloadEntity getDownloadEntity() {
		return mDownloadEntity;
	}

	public void setDownloadedSize(int downloadedSize) {
		mDownloadedSize = downloadedSize;
		mProgress = (mDownloadedSize * 100) / mTotalSize;
	}

	public int getDownloadedSize() {
		return mDownloadedSize;
	}

	public void notifyDownloadStarted() {
		if (mDownloadJobListener != null)
			mDownloadJobListener.downloadStarted(this);
		mProgress = 0;
	}

	public void notifyDownloadCompleted() {
		if (mDownloadJobListener != null)
			mDownloadJobListener.downloadCompleted(this);
		mProgress = 100;
	}

	public void notifyDownloadFatal() {
		if (mDownloadJobListener != null) {
			mDownloadJobListener.downloadFatal(this);
		}
		mProgress = 0;
	}

	public void setStartId(int mStartId) {
		this.mStartId = mStartId;
	}

	public int getStartId() {
		return mStartId;
	}
}
